<?php
/*
Primary Author: Derek Shue
Secondary: Alex Arey
Documentation: Cheng Yi
Updated: 12/10/2011
Module Description: The Reset User module adds/finds/updates/deletes User Password Reset Requests, to facilitate
Password Resets for non-ONYEN logins. 
Currently not implemented.
*/
class Application_Model_DbTable_ResetUser extends Zend_Db_Table_Abstract
{
    protected $_name = 'RESETUSER';

public function getUser($where)
    {

        $row = $this->fetchRow($where);
        if (!$row) {
            throw new Exception("Could not find row $where");
        }
		
	return $row->toArray();
    }

    public function addResetUser($id, $timestamp)
    {
			
		$resetid = $this->getNextKey();
		
        $data = array(
            'ID' => $id,
            'TIMESTAMP' => $timestamp,
			
        );
        $this->insert($data);
		return $resetid;
	}

    public function updateResetUser($resetid, $id, $timestamp)
    {
        $data = array(
            'ID' => $id,
            'TIMESTAMP' => $timestamp,		
        );
		
		$data = array_filter($data);
		
        $this->update($data, 'RESETID = '. (int)$resetid);
    }

    public function deleteResetUser($resetid)
    {
        $this->delete('RESETID =' . (int)$resetid);
    }

	
	public function getNextKey(){
			$sqlquery = $this->select()->from($this->_name, array("MAX(RESETID)"));
			$insertrow = $this->fetchRow($sqlquery)->toArray(); 
			return $insertrow["MAX(RESETID)"] + 1;
	
	}


	
	}



?>
